# -*- coding:utf-8 -*-
class Solution:
    '''
    栈先进后出
    队列先进先出
    '''
    def __init__(self):
        self.stack = list()
        self.min_value = list()

    def push(self, node):
        # write code here
        self.stack.append(node)
        if not self.min_value:
            self.min_value.append(node)
        else:
            self.min_value.append(node)
            for i in range(len(self.min_value)-2, -1, -1):
                if self.min_value[i] > node:
                    mid = self.min_value[i]
                    self.min_value[i] = node
                    self.min_value[i+1] = mid
                else:
                    break
        return node

    def pop(self):
        # write code here
        pop_item = self.stack.pop()
        for i in range(len(self.min_value)-1,-1,-1):
            if self.min_value[i] == pop_item:
                self.min_value.pop(i)
                break
        return pop_item
    def top(self):
        # write code here
        if not self.stack:
            return None
        return self.stack[-1]
    def min(self):
        # write code here
        if not self.min_value:
            return None
        return self.min_value[0]

# a = Solution()
# a.push(2)
# print(a.min())
# a.push(4)
# print(a.min())
# a.push(2)
# print(a.min())
# a.push(3)
# print(a.min())
# a.pop()
# print(a.min_value)
# print(a.min())
# a.pop()
# print(a.min())
# print(a.min_value)
# a.pop()
# print(a.min())
# print(a.min_value)
# a.push(0)
# print(a.min())

